/**
 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
 * agreements.  See the NOTICE file distributed with this work for additional information regarding
 * copyright ownership.  The ASF licenses this file to you under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with the License.  You may obtain
 * a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package org.apache.zookeeper.server.persistence;

import org.apache.zookeeper.server.DataTree;

import java.io.File;
import java.io.IOException;
import java.util.Map;

/**
 * 快照接口，属于持久化层。
 */
public interface SnapShot {

    /**
     * 使用最后一个合法的快照文件反序列化出dataTree和session信息，并且
     * 返回：从快照文件反序列化出的最后的事务id
     *
     * @param dt 数据数会被反序列化到此变量中
     * @param sessions 会把快照文件中的session信息，存储到此map中。
     * @return 从快照文件反序列化出的最后的事务id
     * @throws IOException
     */
    long deserialize(DataTree dt, Map<Long, Integer> sessions) throws IOException;

    /**
     * 持久化datatree和session到一个持久化存储
     * @param dt 将要被序列化的datatree
     * @param sessions client与server之间维护的session信息
     * @throws IOException
     */
    void serialize(DataTree dt, Map<Long, Integer> sessions, File name) throws IOException;

    /**
     * 找到最近的快照文件
     * @return 最近的快照文件
     * @throws IOException
     */
    File findMostRecentSnapshot() throws IOException;

    /**
     * 释放资源、关闭链接
     * @throws IOException
     */
    void close() throws IOException;
} 
